/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package org.whuims.web;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.whuims.entity.News;
import org.whuims.service.account.ShiroDbRealm.ShiroUser;
import org.whuims.service.news.NewsService;

import java.util.List;

/**
 * @author calvin
 */
@Controller
@RequestMapping(value = "/index")
public class IndexController {
    @Autowired
    private NewsService newsService;

    @RequestMapping
    public String index(Model model) {
        List<News> news = newsService.getAllNews();
        model.addAttribute("news", news);
        return "index";
    }

    /**
     * 取出Shiro中的当前用户Id.
     */
    private Long getCurrentUserId() {
        ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
        return user.id;
    }

    @RequestMapping(value = "search", method = RequestMethod.GET)
    public String testSearch() {
        return "doc/search";
    }
}
